<?php
namespace app\index\controller;
use think\Db;
class News extends Base{
    public function news(){
        $keyword=input('get.keyword');
        $customer=Db::name('customer')->where('id',input("param.cus_id"))->find();
    	$navs=Db::name('nav')->where('nav_type',3)->where('cus_id',input("param.cus_id"))->where('state',1)->order('sort asc')->select();
        $comads=Db::name('news')->where('cus_id',input("param.cus_id"))->where('state',1)->order('sort desc')->limit(3)->select();
    	$logo=Db::name('aboutus')->where('cus_id',input("param.cus_id"))->find();
        $banner=Db::name('banner')->where('cus_id',input("param.cus_id"))->where('state',1)->where('mtype',3)->order('sort desc')->find();
        $newcates=Db::name('cate')->where('type',3)->where('cus_id',input("param.cus_id"))->where('state',1)->order('sort desc')->select();
        $news=Db::name('news')->where('cus_id',input("param.cus_id"))->where('state',1)->where('flag',1)->order('sort desc')->find();
        $renews=Db::name('news')->where('cus_id',input("param.cus_id"))->where('state',1)->where('flag',1)->order('id desc')->limit(3)->select();
        if (input('get.cate_id')==0) {
            $allnew=Db::name('news')->where('cus_id',input("param.cus_id"))->where('title','like',"%{$keyword}%")->where('state',1)->order('id desc')->paginate(4);
            $allnews=Db::name('news')->where('cus_id',input("param.cus_id"))->where('title','like',"%{$keyword}%")->where('state',1)->order('id desc')->select();
            $this->assign('cate_id',0);
        }else{
            $allnew=Db::name('news')->where('cus_id',input("param.cus_id"))->where('cate_id',input("param.cate_id"))->where('title','like',"%{$keyword}%")->where('state',1)->order('id desc')->paginate(4);
            $allnews=Db::name('news')->where('cus_id',input("param.cus_id"))->where('cate_id',input("param.cate_id"))->where('title','like',"%{$keyword}%")->where('state',1)->order('id desc')->select();
            $this->assign('cate_id',input('get.cate_id'));
        }
        $data=$allnew->all();
        $this->assign('customer',$customer);
        $this->assign('data',$data);
        $this->assign('allnew',$allnew);
        $this->assign('allnews',$allnews);
        $this->assign('keyword',input('get.keyword'));

        $this->assign('cus_id',input("param.cus_id"));
        $this->assign('navs',$navs);
        // $this->assign('url','http://'.$_SERVER['HTTP_HOST'].'/index.php/index/');
        $this->assign('url','/index.php/index/');
        $this->assign('logo',$logo);
        $this->assign('comads',$comads);
        $this->assign('banner',$banner);
        $this->assign('newcates',$newcates);
        $this->assign('news',$news);
        $this->assign('renews',$renews);
        return $this->fetch();
    }
    public function newsdetail(){
        $keyword=input('get.keyword');
        $customer=Db::name('customer')->where('id',input("param.cus_id"))->find();
        $navs=Db::name('nav')->where('nav_type',3)->where('cus_id',input("param.cus_id"))->where('state',1)->order('sort asc')->select();
        $comads=Db::name('news')->where('cus_id',input("param.cus_id"))->where('state',1)->order('sort desc')->limit(3)->select();
        $banner=Db::name('banner')->where('cus_id',input("param.cus_id"))->where('state',1)->where('mtype',3)->order('sort desc')->find();
    	$detail=Db::name('news')->where('cus_id',input("param.cus_id"))->where('state',1)->where('id',input("param.id"))->find();
        $logo=Db::name('aboutus')->where('cus_id',input("param.cus_id"))->find();
        $renews=Db::name('news')->where('cus_id',input("param.cus_id"))->where('state',1)->where('flag',1)->order('id desc')->select();
        $newcates=Db::name('cate')->where('type',3)->where('cus_id',input("param.cus_id"))->where('state',1)->order('sort desc')->select();
        $this->assign('navs',$navs);
        $this->assign('customer',$customer);
        $this->assign('cus_id',input("param.cus_id"));
        $this->assign('detail',$detail);
        $this->assign('url','/index.php/index/');
        $this->assign('logo',$logo);
        $this->assign('comads',$comads);
        $this->assign('renews',$renews);
        $this->assign('banner',$banner);
        $this->assign('newcates',$newcates);
        $this->assign('cate_id',0);
        $this->assign('keyword',input('get.keyword'));
        return $this->fetch();
    }
}
